#!/bin/bash

set -Eeuxo pipefail

# Change directory to where the script is
cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)/$(basename -- "$0")"

PROTO_ROOT=$(git rev-parse --show-toplevel)/external/apiset

# coin2 order log
protoc -I${PROTO_ROOT} --python_out=. ${PROTO_ROOT}/coin2/exchange/order/*.proto
protoc -I${PROTO_ROOT} --python_out=. ${PROTO_ROOT}/coin2/exchange/*.proto
protoc -I${PROTO_ROOT} --python_out=. ${PROTO_ROOT}/coin2/strategy/*.proto
protoc -I${PROTO_ROOT} --python_out=. ${PROTO_ROOT}/coin2/strategy/linear_model/*.proto
protoc -I${PROTO_ROOT} --python_out=. ${PROTO_ROOT}/coin2/base/*.proto
protoc -I${PROTO_ROOT} --python_out=. ${PROTO_ROOT}/coin2/app/*.proto
protoc -I${PROTO_ROOT} --python_out=. ${PROTO_ROOT}/fastfeature/*.proto

COIN_ROOT="$(git rev-parse --show-toplevel)"
COIN_BINARY_ROOT=$COIN_ROOT/../coin_binary

function deploy_coin2_app {
  mkdir -p $COIN_BINARY_ROOT/coin2-bazel-bin-3.10/$1
  rsync -avh --delete -L $2 $COIN_BINARY_ROOT/coin2-bazel-bin-3.10/$1
}

deploy_coin2_app external/apiset/coin2/app/ \
  'coin2/app/*.py'

deploy_coin2_app external/apiset/coin2/exchange/order/\
  'coin2/exchange/order/*.py'

deploy_coin2_app external/apiset/coin2/exchange/ \
  'coin2/exchange/*.py'

deploy_coin2_app external/apiset/coin2/strategy/ \
  'coin2/strategy/*.py'

deploy_coin2_app external/apiset/coin2/strategy/linear_model/ \
  'coin2/strategy/linear_model/*.py'

deploy_coin2_app external/apiset/coin2/base/ \
  'coin2/base/*.py'

deploy_coin2_app external/apiset/fastfeature/ \
  'fastfeature/*.py'


echo "Build and Copy coin2 proto Successfully!!"
